package com.journaldev.spring.model;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;


@Entity
@Table(name="quanhuyen")
public class District {
	
	public District() {
	}

	public District(int id, String districtName, City belongToCity) {
		super();
		this.id = id;
		this.districtName = districtName;
		this.belongToCity = belongToCity;
	}

	@Id
	@Column(name="id_quanhuyen")
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column(name="ten_quanhuyen")
	private String districtName;

	public String getDistrictName() {
		return districtName;
	}

	public void setDistrictName(String districtName) {
		this.districtName = districtName;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "id_thanhpho")
	private City belongToCity;

	public City getBelongToCity() {
		return belongToCity;
	}

	public void setBelongToCity(City belongToCity) {
		this.belongToCity = belongToCity;
	}
	
	//orphanRemoval : when set to true , and delete 1 object in set ==> delete that object in db too
	@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "belongToDistrict", orphanRemoval = true)
	private Set<Ward> ward;
	
	public void setWard(Set<Ward> ward) {
		this.ward = ward;
	}
	
	public Set<Ward> getWard() {
		return ward;
	}
}
